publicintIndexOf(T item) { var current = _first; var index = 0; while (current != null) { if (Equals(current.Value, item)) { return index; }
index++; current = current.Next; }
return-1; }
public T[] ToArray() { var array = new T[_size]; var current = _first; var index = 0; while (current != null) { array[index++] = current.Value; current = current.Next; }
return array; }
publicintSize() { return _size; }
privateboolIsEmpty() { return _first == null; }
private Node<T> GetPrevious(Node<T> node) { var current = _first; while (current != null) { if (current.Next == node) { return current; } current = current.Next; }
// first last // origin [10 -> 20 -> 30] // last first // reverse [10 <- 20 <- 30]
publicvoidReverse() { var first = _first; var second = _first.Next; while(second != null) { var third = second.Next; second.Next = first; first = second; second = third; }